/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2025-06-07 02:19:56
 * @LastEditors: sueRimn
 * @LastEditTime: 2025-08-26 19:49:52
 */
#include "led.h"
#include "public.h"

#include "stdio.h"

uint8_t ucLedBlueStat;
uint8_t ucLedRedStat;
uint8_t ucLedGreenStat;

void ledTimeCallback()
{
    static uint8_t ucLedBlueDir = 1;//1 pwm+ 0-
    static uint8_t ucLedRedDir = 1;
    static uint8_t ucLedGreenDir = 1;

    if (ucLedBlueStat == LED_BREA)
    {
        if (LED_BLUE_LIGHT < LED_BLUE_LIGHT_STEP)
        {
            ucLedBlueDir = 1;
        }
        else if (LED_BLUE_LIGHT >= LED_BLUE_LIGHT_MAX)
        {
            ucLedBlueDir = 0;
        }

        if (ucLedBlueDir == 1)
        {
            LED_BLUE_LIGHT += LED_BLUE_LIGHT_STEP;
        }
        else
        {
            LED_BLUE_LIGHT -= LED_BLUE_LIGHT_STEP;
        }
    }

    if (ucLedRedStat == LED_BREA)
    {
        if (LED_RED_LIGHT < LED_RED_LIGHT_STEP)
        {
            ucLedRedDir = 1;
        }
        else if (LED_RED_LIGHT >= LED_RED_LIGHT_MAX)
        {
            ucLedRedDir = 0;
        }

        if (ucLedRedDir == 1)
        {
            LED_RED_LIGHT += LED_RED_LIGHT_STEP;
        }
        else
        {
            LED_RED_LIGHT -= LED_RED_LIGHT_STEP;
        }
    }

    if (ucLedGreenStat == LED_BREA)
    {
        if (LEDG_REEN_LIGHT < LEDG_REEN_LIGHT_STEP)
        {
            ucLedGreenDir = 1;
        }
        else if (LEDG_REEN_LIGHT >= LEDG_REEN_LIGHT_MAX)
        {
            ucLedGreenDir = 0;
        }

        if (ucLedGreenDir == 1)
        {
            LEDG_REEN_LIGHT += LEDG_REEN_LIGHT_STEP;
        }
        else
        {
            LEDG_REEN_LIGHT -= LEDG_REEN_LIGHT_STEP;
        }
    }
}

void ledRunTask(void)
{
    if (ucLedBlueStat == LED_ON)
    {
        LED_BLUE_LIGHT = LED_BLUE_LIGHT_MAX;
    }
    else if (ucLedBlueStat == LED_OFF)
    {
        LED_BLUE_LIGHT = 0;
    }

    if (ucLedRedStat == LED_ON)
    {
        LED_RED_LIGHT = LED_RED_LIGHT_MAX;
    }
    else if (ucLedRedStat == LED_OFF)
    {
        LED_RED_LIGHT = 0;
    }

    if (ucLedGreenStat == LED_ON)
    {
        LEDG_REEN_LIGHT = LEDG_REEN_LIGHT_MAX;
    }
    else if (ucLedGreenStat == LED_OFF)
    {
        LEDG_REEN_LIGHT = 0;
    }
    //		
    //		printf("2ucLedBlueStat = %d ucLedRedStat = %d ucLedGreenStat = %d\r\n",LED_BLUE_LIGHT,LED_RED_LIGHT,LEDG_REEN_LIGHT);
}

void led_init(void)
{
    //    LED_BLUE_LIGHT = 0;       //蓝  占比第二
    //    LED_RED_LIGHT = 0;        //红  占比最高
    //    LEDG_REEN_LIGHT = 0;      //绿  占比最低

    setLedStat(LED_ON, LED_ON, LED_ON);
}

void setLedStat(uint8_t ucBlueLedStat, uint8_t ucRedLedStat, uint8_t ucGreenLedStat)
{
    //		printf("1ucLedBlueStat = %d ucLedRedStat = %d ucLedGreenStat = %d\r\n",ucLedBlueStat,ucLedRedStat,ucLedGreenStat);
    if (ucBlueLedStat != LED_NULL)
        ucLedBlueStat = ucBlueLedStat;
    if (ucRedLedStat != LED_NULL)
        ucLedRedStat = ucRedLedStat;
    if (ucGreenLedStat != LED_NULL)
        ucLedGreenStat = ucGreenLedStat;
}